package com.example.asproject1801_1.requestpermisson;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;

import com.example.asproject1801_1.R;

public class CallActivity2 extends AppCompatActivity implements PermissionUtils.PermissionGrant {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_call2);
    }

    /* 拨打电话的函数*/
    private void callPhone(String num) {
        Intent intent = new Intent(Intent.ACTION_CALL);
        Uri uri = Uri.parse("tel:" + num);
        intent.setData(uri);
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
        }
        startActivity(intent);
    }
    public void onClick(View view) {
        PermissionUtils.requestPermission(this,PermissionUtils.CODE_PHONE,this);
    }
    // 表示被授权之后，可以调用的方法
    @Override
    public void onPermissionGranted(int requestCode) {
        callPhone("10086");
    }
    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
                                           @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        PermissionUtils.requestPermissionsResult(this,requestCode,permissions,grantResults,this);
    }
}